from Tkinter import *
class ButtonHandler:
    """It's a callable object bind with button name as request'"""
    def __init__(self,name,ctl):
        self.name=name
        self.ctl=ctl
    def __call__(self):
        self.ctl.handle_request(self.name)

class TaskListView:
    "Display task list"
    def __init__(self,ctl,root,x=9800,y=450):
        self.ctl=ctl #ctl is mainDoc
        self.root=root
        self.buttonList=[]
        self.x=x#Node button start pos
        self.y=y

    def Show(self):
        "Create buttons list"
        xpos=self.x
        ypos=self.y
        i=0
        for task in self.taskList:
            #print task
            b=Button(self.root)
            b.place(x=xpos/15,y=ypos/15,width=1855/15,height=375/15)
            self.buttonList.append(b)
            b.config(text=task)
            b.config(command=ButtonHandler(task,self.ctl))
            i+=1
            ypos+=475

    def Update(self,doc):
        "Update buttons list"
        self.buttonList=[]
        self.taskList=doc.get_task_list()
        self.Show()

class TaskListAdapter:
    "Adapter bind with taskM"
    def __init__(self, doc):
        self.doc = doc

    def handle_request(self,taskName):
        "View will call this method"
        task=self.doc.load_task(taskName)






